﻿using System;
using System.Collections.Generic;
using System.Windows.Controls;
using EasySL.Controls;

namespace EasySL.UI.Controls
{
    public partial class AudioPlayerSample : UserControl
    {
        public AudioPlayerSample()
        {
            InitializeComponent();

            audioList = new List<AudioEntity>()
            {
                new AudioEntity()
                {
                    Title = "简单爱",
                    Artist = "周杰伦",
                    Url = "http://www.kerric-china.com/jiandanai.wma"
                },
                new AudioEntity()
                {
                    Title = "摘下满天星",
                    Artist = "郑少秋",
                    Url = "http://www.cdsf.org.cn/data/2008-10-17/1_1224224625.mp3"
                },
                new AudioEntity()
                {
                    Title = "你最珍贵",
                    Artist = "张学友",
                    Url = "http://blog.csonline.com.cn/Blog/081121/FileUP/0811210001_Wave.mp3"
                },
                new AudioEntity()
                {
                    Title = "只记今朝笑",
                    Artist = "林青霞",
                    Url = "http://www.dengdengba.com/upload/ring/20090619160111834.mp3"
                },  
                new AudioEntity()
                {
                    Title = "找一个地方",
                    Artist = "王杰",
                    Url = "http://www.michelle-ye.com/mp3/6_Treasure_Raiders_main.mp3"
                }
            };

            this.player.PlaylistEntry = audioList[index];

            this.player.OnPrev += () =>
            {
                if (index == 0)
                    index = audioList.Count - 1;
                else
                    index = index - 1;

                Play();              
            };

            this.player.OnNext += () =>
            {
                if (index == audioList.Count - 1)
                    index = 0;
                else
                    index = index + 1;

                Play(); 
            };

            this.player.OnEnd += () =>
            {
                if (index == audioList.Count - 1)
                    index = 0;
                else
                    index = index + 1;

                Play(); 
            };
        }

        private void Play()
        {
            this.player.PlaylistEntry = audioList[index];
        }

        private int index = 0;
        private List<AudioEntity> audioList;
    }
}
